package com.sphd.education.base;
import android.app.Dialog;
import android.graphics.drawable.AnimationDrawable;
import android.support.v4.app.Fragment;
import android.widget.ImageView;
import android.widget.Toast;

import com.sphd.education.R;

import org.json.JSONArray;
import org.json.JSONObject;

/**
 * Created by Hu on 2015/12/2.
 */
public abstract class BaseVPFragment extends Fragment {
    private Dialog dialog;
    /** Fragment当前状态是否可见 */
    protected boolean isVisible;
    public abstract void myNet();
    public abstract void getList( String string);
    public abstract void getList( JSONObject jsonObject);
    public abstract void getList( JSONArray jsonArray);

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);

        if(getUserVisibleHint()) {
            isVisible = true;
            onVisible();
        } else {
            isVisible = false;
            onInvisible();
        }
    }

    /**
     * 可见
     */
    protected void onVisible() {
        lazyLoad();
    }

    /**
     * 不可见
     */
    protected void onInvisible() {

    }

    /**
     * 延迟加载
     * 子类必须重写此方法
     */
    protected abstract void lazyLoad();


    public void toast(String msg){
        Toast.makeText(getContext(),msg,Toast.LENGTH_SHORT).show();
    }
    public void showMyDialog() {
        dialog=new Dialog(getContext(), R.style.Translucent_NoTitle);
        dialog.setContentView(R.layout.customprogressdialog);
        dialog.setCanceledOnTouchOutside(false);
        ImageView imageView = (ImageView) dialog.findViewById(R.id.loadingImageView);
        AnimationDrawable spinner = (AnimationDrawable) imageView.getBackground();
        // 开始动画
        spinner.start();
        dialog.show();
    }
    public void dismissMyDialog() {
        dialog.dismiss();
    }
}
